using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace Medianamik.Core.DAL.SubSonicDAL
{
	/// <summary>
	/// Strongly-typed collection for the Node class.
	/// </summary>
    [Serializable]
	public partial class NodeCollection : ActiveList<Node, NodeCollection>
	{	   
		public NodeCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>NodeCollection</returns>
		public NodeCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                Node o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the medianamik_Node table.
	/// </summary>
	[Serializable]
	public partial class Node : ActiveRecord<Node>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Node()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public Node(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public Node(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public Node(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("medianamik_Node", TableType.Table, DataService.GetInstance("MedianamikProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarNodeId = new TableSchema.TableColumn(schema);
				colvarNodeId.ColumnName = "NodeId";
				colvarNodeId.DataType = DbType.Guid;
				colvarNodeId.MaxLength = 0;
				colvarNodeId.AutoIncrement = false;
				colvarNodeId.IsNullable = false;
				colvarNodeId.IsPrimaryKey = true;
				colvarNodeId.IsForeignKey = false;
				colvarNodeId.IsReadOnly = false;
				
						colvarNodeId.DefaultSetting = @"(newid())";
				colvarNodeId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarNodeId);
				
				TableSchema.TableColumn colvarParentNodeId = new TableSchema.TableColumn(schema);
				colvarParentNodeId.ColumnName = "ParentNodeId";
				colvarParentNodeId.DataType = DbType.Guid;
				colvarParentNodeId.MaxLength = 0;
				colvarParentNodeId.AutoIncrement = false;
				colvarParentNodeId.IsNullable = true;
				colvarParentNodeId.IsPrimaryKey = false;
				colvarParentNodeId.IsForeignKey = true;
				colvarParentNodeId.IsReadOnly = false;
				colvarParentNodeId.DefaultSetting = @"";
				
					colvarParentNodeId.ForeignKeyTableName = "medianamik_Node";
				schema.Columns.Add(colvarParentNodeId);
				
				TableSchema.TableColumn colvarTypeId = new TableSchema.TableColumn(schema);
				colvarTypeId.ColumnName = "TypeId";
				colvarTypeId.DataType = DbType.Guid;
				colvarTypeId.MaxLength = 0;
				colvarTypeId.AutoIncrement = false;
				colvarTypeId.IsNullable = false;
				colvarTypeId.IsPrimaryKey = false;
				colvarTypeId.IsForeignKey = true;
				colvarTypeId.IsReadOnly = false;
				colvarTypeId.DefaultSetting = @"";
				
					colvarTypeId.ForeignKeyTableName = "medianamik_Type";
				schema.Columns.Add(colvarTypeId);
				
				TableSchema.TableColumn colvarCreatedOn = new TableSchema.TableColumn(schema);
				colvarCreatedOn.ColumnName = "CreatedOn";
				colvarCreatedOn.DataType = DbType.DateTime;
				colvarCreatedOn.MaxLength = 0;
				colvarCreatedOn.AutoIncrement = false;
				colvarCreatedOn.IsNullable = false;
				colvarCreatedOn.IsPrimaryKey = false;
				colvarCreatedOn.IsForeignKey = false;
				colvarCreatedOn.IsReadOnly = false;
				
						colvarCreatedOn.DefaultSetting = @"(getdate())";
				colvarCreatedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedOn);
				
				TableSchema.TableColumn colvarCreatedBy = new TableSchema.TableColumn(schema);
				colvarCreatedBy.ColumnName = "CreatedBy";
				colvarCreatedBy.DataType = DbType.String;
				colvarCreatedBy.MaxLength = 50;
				colvarCreatedBy.AutoIncrement = false;
				colvarCreatedBy.IsNullable = true;
				colvarCreatedBy.IsPrimaryKey = false;
				colvarCreatedBy.IsForeignKey = false;
				colvarCreatedBy.IsReadOnly = false;
				colvarCreatedBy.DefaultSetting = @"";
				colvarCreatedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedBy);
				
				TableSchema.TableColumn colvarModifiedOn = new TableSchema.TableColumn(schema);
				colvarModifiedOn.ColumnName = "ModifiedOn";
				colvarModifiedOn.DataType = DbType.DateTime;
				colvarModifiedOn.MaxLength = 0;
				colvarModifiedOn.AutoIncrement = false;
				colvarModifiedOn.IsNullable = true;
				colvarModifiedOn.IsPrimaryKey = false;
				colvarModifiedOn.IsForeignKey = false;
				colvarModifiedOn.IsReadOnly = false;
				colvarModifiedOn.DefaultSetting = @"";
				colvarModifiedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarModifiedOn);
				
				TableSchema.TableColumn colvarModifiedBy = new TableSchema.TableColumn(schema);
				colvarModifiedBy.ColumnName = "ModifiedBy";
				colvarModifiedBy.DataType = DbType.String;
				colvarModifiedBy.MaxLength = 50;
				colvarModifiedBy.AutoIncrement = false;
				colvarModifiedBy.IsNullable = true;
				colvarModifiedBy.IsPrimaryKey = false;
				colvarModifiedBy.IsForeignKey = false;
				colvarModifiedBy.IsReadOnly = false;
				colvarModifiedBy.DefaultSetting = @"";
				colvarModifiedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarModifiedBy);
				
				TableSchema.TableColumn colvarFlags = new TableSchema.TableColumn(schema);
				colvarFlags.ColumnName = "Flags";
				colvarFlags.DataType = DbType.Int32;
				colvarFlags.MaxLength = 0;
				colvarFlags.AutoIncrement = false;
				colvarFlags.IsNullable = false;
				colvarFlags.IsPrimaryKey = false;
				colvarFlags.IsForeignKey = false;
				colvarFlags.IsReadOnly = false;
				
						colvarFlags.DefaultSetting = @"((0))";
				colvarFlags.ForeignKeyTableName = "";
				schema.Columns.Add(colvarFlags);
				
				TableSchema.TableColumn colvarIsDeleted = new TableSchema.TableColumn(schema);
				colvarIsDeleted.ColumnName = "IsDeleted";
				colvarIsDeleted.DataType = DbType.Boolean;
				colvarIsDeleted.MaxLength = 0;
				colvarIsDeleted.AutoIncrement = false;
				colvarIsDeleted.IsNullable = false;
				colvarIsDeleted.IsPrimaryKey = false;
				colvarIsDeleted.IsForeignKey = false;
				colvarIsDeleted.IsReadOnly = false;
				
						colvarIsDeleted.DefaultSetting = @"((0))";
				colvarIsDeleted.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsDeleted);
				
				TableSchema.TableColumn colvarPath = new TableSchema.TableColumn(schema);
				colvarPath.ColumnName = "Path";
				colvarPath.DataType = DbType.AnsiString;
				colvarPath.MaxLength = 500;
				colvarPath.AutoIncrement = false;
				colvarPath.IsNullable = false;
				colvarPath.IsPrimaryKey = false;
				colvarPath.IsForeignKey = false;
				colvarPath.IsReadOnly = false;
				colvarPath.DefaultSetting = @"";
				colvarPath.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPath);
				
				TableSchema.TableColumn colvarDepth = new TableSchema.TableColumn(schema);
				colvarDepth.ColumnName = "Depth";
				colvarDepth.DataType = DbType.Int32;
				colvarDepth.MaxLength = 0;
				colvarDepth.AutoIncrement = false;
				colvarDepth.IsNullable = false;
				colvarDepth.IsPrimaryKey = false;
				colvarDepth.IsForeignKey = false;
				colvarDepth.IsReadOnly = false;
				colvarDepth.DefaultSetting = @"";
				colvarDepth.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDepth);
				
				TableSchema.TableColumn colvarPosition = new TableSchema.TableColumn(schema);
				colvarPosition.ColumnName = "Position";
				colvarPosition.DataType = DbType.Int16;
				colvarPosition.MaxLength = 0;
				colvarPosition.AutoIncrement = false;
				colvarPosition.IsNullable = false;
				colvarPosition.IsPrimaryKey = false;
				colvarPosition.IsForeignKey = false;
				colvarPosition.IsReadOnly = false;
				colvarPosition.DefaultSetting = @"";
				colvarPosition.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPosition);
				
				TableSchema.TableColumn colvarEditedOn = new TableSchema.TableColumn(schema);
				colvarEditedOn.ColumnName = "EditedOn";
				colvarEditedOn.DataType = DbType.DateTime;
				colvarEditedOn.MaxLength = 0;
				colvarEditedOn.AutoIncrement = false;
				colvarEditedOn.IsNullable = true;
				colvarEditedOn.IsPrimaryKey = false;
				colvarEditedOn.IsForeignKey = false;
				colvarEditedOn.IsReadOnly = false;
				colvarEditedOn.DefaultSetting = @"";
				colvarEditedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarEditedOn);
				
				TableSchema.TableColumn colvarEditedBy = new TableSchema.TableColumn(schema);
				colvarEditedBy.ColumnName = "EditedBy";
				colvarEditedBy.DataType = DbType.String;
				colvarEditedBy.MaxLength = 50;
				colvarEditedBy.AutoIncrement = false;
				colvarEditedBy.IsNullable = true;
				colvarEditedBy.IsPrimaryKey = false;
				colvarEditedBy.IsForeignKey = false;
				colvarEditedBy.IsReadOnly = false;
				colvarEditedBy.DefaultSetting = @"";
				colvarEditedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarEditedBy);
				
				TableSchema.TableColumn colvarIsSubEntity = new TableSchema.TableColumn(schema);
				colvarIsSubEntity.ColumnName = "IsSubEntity";
				colvarIsSubEntity.DataType = DbType.Boolean;
				colvarIsSubEntity.MaxLength = 0;
				colvarIsSubEntity.AutoIncrement = false;
				colvarIsSubEntity.IsNullable = false;
				colvarIsSubEntity.IsPrimaryKey = false;
				colvarIsSubEntity.IsForeignKey = false;
				colvarIsSubEntity.IsReadOnly = false;
				
						colvarIsSubEntity.DefaultSetting = @"((0))";
				colvarIsSubEntity.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsSubEntity);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["MedianamikProvider"].AddSchema("medianamik_Node",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("NodeId")]
		[Bindable(true)]
		public Guid NodeId 
		{
			get { return GetColumnValue<Guid>(Columns.NodeId); }
			set { SetColumnValue(Columns.NodeId, value); }
		}
		  
		[XmlAttribute("ParentNodeId")]
		[Bindable(true)]
		public Guid? ParentNodeId 
		{
			get { return GetColumnValue<Guid?>(Columns.ParentNodeId); }
			set { SetColumnValue(Columns.ParentNodeId, value); }
		}
		  
		[XmlAttribute("TypeId")]
		[Bindable(true)]
		public Guid TypeId 
		{
			get { return GetColumnValue<Guid>(Columns.TypeId); }
			set { SetColumnValue(Columns.TypeId, value); }
		}
		  
		[XmlAttribute("CreatedOn")]
		[Bindable(true)]
		public DateTime CreatedOn 
		{
			get { return GetColumnValue<DateTime>(Columns.CreatedOn); }
			set { SetColumnValue(Columns.CreatedOn, value); }
		}
		  
		[XmlAttribute("CreatedBy")]
		[Bindable(true)]
		public string CreatedBy 
		{
			get { return GetColumnValue<string>(Columns.CreatedBy); }
			set { SetColumnValue(Columns.CreatedBy, value); }
		}
		  
		[XmlAttribute("ModifiedOn")]
		[Bindable(true)]
		public DateTime? ModifiedOn 
		{
			get { return GetColumnValue<DateTime?>(Columns.ModifiedOn); }
			set { SetColumnValue(Columns.ModifiedOn, value); }
		}
		  
		[XmlAttribute("ModifiedBy")]
		[Bindable(true)]
		public string ModifiedBy 
		{
			get { return GetColumnValue<string>(Columns.ModifiedBy); }
			set { SetColumnValue(Columns.ModifiedBy, value); }
		}
		  
		[XmlAttribute("Flags")]
		[Bindable(true)]
		public int Flags 
		{
			get { return GetColumnValue<int>(Columns.Flags); }
			set { SetColumnValue(Columns.Flags, value); }
		}
		  
		[XmlAttribute("IsDeleted")]
		[Bindable(true)]
		public bool IsDeleted 
		{
			get { return GetColumnValue<bool>(Columns.IsDeleted); }
			set { SetColumnValue(Columns.IsDeleted, value); }
		}
		  
		[XmlAttribute("Path")]
		[Bindable(true)]
		public string Path 
		{
			get { return GetColumnValue<string>(Columns.Path); }
			set { SetColumnValue(Columns.Path, value); }
		}
		  
		[XmlAttribute("Depth")]
		[Bindable(true)]
		public int Depth 
		{
			get { return GetColumnValue<int>(Columns.Depth); }
			set { SetColumnValue(Columns.Depth, value); }
		}
		  
		[XmlAttribute("Position")]
		[Bindable(true)]
		public short Position 
		{
			get { return GetColumnValue<short>(Columns.Position); }
			set { SetColumnValue(Columns.Position, value); }
		}
		  
		[XmlAttribute("EditedOn")]
		[Bindable(true)]
		public DateTime? EditedOn 
		{
			get { return GetColumnValue<DateTime?>(Columns.EditedOn); }
			set { SetColumnValue(Columns.EditedOn, value); }
		}
		  
		[XmlAttribute("EditedBy")]
		[Bindable(true)]
		public string EditedBy 
		{
			get { return GetColumnValue<string>(Columns.EditedBy); }
			set { SetColumnValue(Columns.EditedBy, value); }
		}
		  
		[XmlAttribute("IsSubEntity")]
		[Bindable(true)]
		public bool IsSubEntity 
		{
			get { return GetColumnValue<bool>(Columns.IsSubEntity); }
			set { SetColumnValue(Columns.IsSubEntity, value); }
		}
		
		#endregion
		
		
		#region PrimaryKey Methods		
		
        protected override void SetPrimaryKey(object oValue)
        {
            base.SetPrimaryKey(oValue);
            
            SetPKValues();
        }
        
		
		private Medianamik.Core.DAL.SubSonicDAL.NodeCollection colChildNodeRecords;
		public Medianamik.Core.DAL.SubSonicDAL.NodeCollection ChildNodeRecords()
		{
			if(colChildNodeRecords == null)
			{
				colChildNodeRecords = new Medianamik.Core.DAL.SubSonicDAL.NodeCollection().Where(Node.Columns.ParentNodeId, NodeId).Load();
				colChildNodeRecords.ListChanged += new ListChangedEventHandler(colChildNodeRecords_ListChanged);
			}
			return colChildNodeRecords;
		}
				
		void colChildNodeRecords_ListChanged(object sender, ListChangedEventArgs e)
		{
            if (e.ListChangedType == ListChangedType.ItemAdded)
            {
		        // Set foreign key value
		        colChildNodeRecords[e.NewIndex].ParentNodeId = NodeId;
				colChildNodeRecords.ListChanged += new ListChangedEventHandler(colChildNodeRecords_ListChanged);
            }
		}
		private Medianamik.Core.DAL.SubSonicDAL.NodeInstanceCollection colNodeInstanceRecords;
		public Medianamik.Core.DAL.SubSonicDAL.NodeInstanceCollection NodeInstanceRecords()
		{
			if(colNodeInstanceRecords == null)
			{
				colNodeInstanceRecords = new Medianamik.Core.DAL.SubSonicDAL.NodeInstanceCollection().Where(NodeInstance.Columns.NodeId, NodeId).Load();
				colNodeInstanceRecords.ListChanged += new ListChangedEventHandler(colNodeInstanceRecords_ListChanged);
			}
			return colNodeInstanceRecords;
		}
				
		void colNodeInstanceRecords_ListChanged(object sender, ListChangedEventArgs e)
		{
            if (e.ListChangedType == ListChangedType.ItemAdded)
            {
		        // Set foreign key value
		        colNodeInstanceRecords[e.NewIndex].NodeId = NodeId;
				colNodeInstanceRecords.ListChanged += new ListChangedEventHandler(colNodeInstanceRecords_ListChanged);
            }
		}
		private Medianamik.Core.DAL.SubSonicDAL.NodePermissionCollection colNodePermissionRecords;
		public Medianamik.Core.DAL.SubSonicDAL.NodePermissionCollection NodePermissionRecords()
		{
			if(colNodePermissionRecords == null)
			{
				colNodePermissionRecords = new Medianamik.Core.DAL.SubSonicDAL.NodePermissionCollection().Where(NodePermission.Columns.NodeId, NodeId).Load();
				colNodePermissionRecords.ListChanged += new ListChangedEventHandler(colNodePermissionRecords_ListChanged);
			}
			return colNodePermissionRecords;
		}
				
		void colNodePermissionRecords_ListChanged(object sender, ListChangedEventArgs e)
		{
            if (e.ListChangedType == ListChangedType.ItemAdded)
            {
		        // Set foreign key value
		        colNodePermissionRecords[e.NewIndex].NodeId = NodeId;
				colNodePermissionRecords.ListChanged += new ListChangedEventHandler(colNodePermissionRecords_ListChanged);
            }
		}
        //private Medianamik.Core.DAL.SubSonicDAL.NodePropertyValueCollection colNodePropertyValueRecords;
        //public Medianamik.Core.DAL.SubSonicDAL.NodePropertyValueCollection NodePropertyValueRecords()
        //{
        //    if(colNodePropertyValueRecords == null)
        //    {
        //        colNodePropertyValueRecords = new Medianamik.Core.DAL.SubSonicDAL.NodePropertyValueCollection().Where(NodePropertyValue.Columns.NodeId, NodeId).Load();
        //        colNodePropertyValueRecords.ListChanged += new ListChangedEventHandler(colNodePropertyValueRecords_ListChanged);
        //    }
        //    return colNodePropertyValueRecords;
        //}
				
        //void colNodePropertyValueRecords_ListChanged(object sender, ListChangedEventArgs e)
        //{
        //    if (e.ListChangedType == ListChangedType.ItemAdded)
        //    {
        //        // Set foreign key value
        //        colNodePropertyValueRecords[e.NewIndex].NodeId = NodeId;
        //        colNodePropertyValueRecords.ListChanged += new ListChangedEventHandler(colNodePropertyValueRecords_ListChanged);
        //    }
        //}
		private Medianamik.Core.DAL.SubSonicDAL.NodeRevisionCollection colNodeRevisionRecords;
		public Medianamik.Core.DAL.SubSonicDAL.NodeRevisionCollection NodeRevisionRecords()
		{
			if(colNodeRevisionRecords == null)
			{
				colNodeRevisionRecords = new Medianamik.Core.DAL.SubSonicDAL.NodeRevisionCollection().Where(NodeRevision.Columns.NodeId, NodeId).Load();
				colNodeRevisionRecords.ListChanged += new ListChangedEventHandler(colNodeRevisionRecords_ListChanged);
			}
			return colNodeRevisionRecords;
		}
				
		void colNodeRevisionRecords_ListChanged(object sender, ListChangedEventArgs e)
		{
            if (e.ListChangedType == ListChangedType.ItemAdded)
            {
		        // Set foreign key value
		        colNodeRevisionRecords[e.NewIndex].NodeId = NodeId;
				colNodeRevisionRecords.ListChanged += new ListChangedEventHandler(colNodeRevisionRecords_ListChanged);
            }
		}
		#endregion
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a Node ActiveRecord object related to this Node
		/// 
		/// </summary>
		public Medianamik.Core.DAL.SubSonicDAL.Node ParentNode
		{
			get { return Medianamik.Core.DAL.SubSonicDAL.Node.FetchByID(this.ParentNodeId); }
			set { SetColumnValue("ParentNodeId", value.NodeId); }
		}
		
		
		/// <summary>
		/// Returns a Type ActiveRecord object related to this Node
		/// 
		/// </summary>
		public Medianamik.Core.DAL.SubSonicDAL.Type Type
		{
			get { return Medianamik.Core.DAL.SubSonicDAL.Type.FetchByID(this.TypeId); }
			set { SetColumnValue("TypeId", value.TypeId); }
		}
		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid varNodeId,Guid? varParentNodeId,Guid varTypeId,DateTime varCreatedOn,string varCreatedBy,DateTime? varModifiedOn,string varModifiedBy,int varFlags,bool varIsDeleted,string varPath,int varDepth,short varPosition,DateTime? varEditedOn,string varEditedBy,bool varIsSubEntity)
		{
			Node item = new Node();
			
			item.NodeId = varNodeId;
			
			item.ParentNodeId = varParentNodeId;
			
			item.TypeId = varTypeId;
			
			item.CreatedOn = varCreatedOn;
			
			item.CreatedBy = varCreatedBy;
			
			item.ModifiedOn = varModifiedOn;
			
			item.ModifiedBy = varModifiedBy;
			
			item.Flags = varFlags;
			
			item.IsDeleted = varIsDeleted;
			
			item.Path = varPath;
			
			item.Depth = varDepth;
			
			item.Position = varPosition;
			
			item.EditedOn = varEditedOn;
			
			item.EditedBy = varEditedBy;
			
			item.IsSubEntity = varIsSubEntity;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(Guid varNodeId,Guid? varParentNodeId,Guid varTypeId,DateTime varCreatedOn,string varCreatedBy,DateTime? varModifiedOn,string varModifiedBy,int varFlags,bool varIsDeleted,string varPath,int varDepth,short varPosition,DateTime? varEditedOn,string varEditedBy,bool varIsSubEntity)
		{
			Node item = new Node();
			
				item.NodeId = varNodeId;
			
				item.ParentNodeId = varParentNodeId;
			
				item.TypeId = varTypeId;
			
				item.CreatedOn = varCreatedOn;
			
				item.CreatedBy = varCreatedBy;
			
				item.ModifiedOn = varModifiedOn;
			
				item.ModifiedBy = varModifiedBy;
			
				item.Flags = varFlags;
			
				item.IsDeleted = varIsDeleted;
			
				item.Path = varPath;
			
				item.Depth = varDepth;
			
				item.Position = varPosition;
			
				item.EditedOn = varEditedOn;
			
				item.EditedBy = varEditedBy;
			
				item.IsSubEntity = varIsSubEntity;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn NodeIdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn ParentNodeIdColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn TypeIdColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn CreatedOnColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn CreatedByColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn ModifiedOnColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn ModifiedByColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn FlagsColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        public static TableSchema.TableColumn IsDeletedColumn
        {
            get { return Schema.Columns[8]; }
        }
        
        
        
        public static TableSchema.TableColumn PathColumn
        {
            get { return Schema.Columns[9]; }
        }
        
        
        
        public static TableSchema.TableColumn DepthColumn
        {
            get { return Schema.Columns[10]; }
        }
        
        
        
        public static TableSchema.TableColumn PositionColumn
        {
            get { return Schema.Columns[11]; }
        }
        
        
        
        public static TableSchema.TableColumn EditedOnColumn
        {
            get { return Schema.Columns[12]; }
        }
        
        
        
        public static TableSchema.TableColumn EditedByColumn
        {
            get { return Schema.Columns[13]; }
        }
        
        
        
        public static TableSchema.TableColumn IsSubEntityColumn
        {
            get { return Schema.Columns[14]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string NodeId = @"NodeId";
			 public static string ParentNodeId = @"ParentNodeId";
			 public static string TypeId = @"TypeId";
			 public static string CreatedOn = @"CreatedOn";
			 public static string CreatedBy = @"CreatedBy";
			 public static string ModifiedOn = @"ModifiedOn";
			 public static string ModifiedBy = @"ModifiedBy";
			 public static string Flags = @"Flags";
			 public static string IsDeleted = @"IsDeleted";
			 public static string Path = @"Path";
			 public static string Depth = @"Depth";
			 public static string Position = @"Position";
			 public static string EditedOn = @"EditedOn";
			 public static string EditedBy = @"EditedBy";
			 public static string IsSubEntity = @"IsSubEntity";
						
		}
		#endregion
		
		#region Update PK Collections
		
        public void SetPKValues()
        {
                if (colChildNodeRecords != null)
                {
                    foreach (Medianamik.Core.DAL.SubSonicDAL.Node item in colChildNodeRecords)
                    {
                        if (item.ParentNodeId != NodeId)
                        {
                            item.ParentNodeId = NodeId;
                        }
                    }
               }
		
                if (colNodeInstanceRecords != null)
                {
                    foreach (Medianamik.Core.DAL.SubSonicDAL.NodeInstance item in colNodeInstanceRecords)
                    {
                        if (item.NodeId != NodeId)
                        {
                            item.NodeId = NodeId;
                        }
                    }
               }
		
                if (colNodePermissionRecords != null)
                {
                    foreach (Medianamik.Core.DAL.SubSonicDAL.NodePermission item in colNodePermissionRecords)
                    {
                        if (item.NodeId != NodeId)
                        {
                            item.NodeId = NodeId;
                        }
                    }
               }
	
		
                if (colNodeRevisionRecords != null)
                {
                    foreach (Medianamik.Core.DAL.SubSonicDAL.NodeRevision item in colNodeRevisionRecords)
                    {
                        if (item.NodeId != NodeId)
                        {
                            item.NodeId = NodeId;
                        }
                    }
               }
		}
        #endregion
    
        #region Deep Save
		
        public void DeepSave()
        {
            Save();
            
                if (colChildNodeRecords != null)
                {
                    colChildNodeRecords.SaveAll();
               }
		
                if (colNodeInstanceRecords != null)
                {
                    colNodeInstanceRecords.SaveAll();
               }
		
                if (colNodePermissionRecords != null)
                {
                    colNodePermissionRecords.SaveAll();
               }
		
		
                if (colNodeRevisionRecords != null)
                {
                    colNodeRevisionRecords.SaveAll();
               }
		}
        #endregion
	}
}
